import * as zrender from 'zrender'

function configStyle(origin,news) {
    if(news && typeof news=='object') {
         for(let key in news) {
            origin[key] = news[key]
         }
    }
    return origin
}

export const createCircle = ([cx,cy],r,style)=> {
    let defaultStyle = {
        fill: 'none',
        stroke: '#F00',
    }
   return new zrender.Circle({
    shape: {
        cx,
        cy,
        r
    },
    style:configStyle(defaultStyle,style),
    cursor:'move',
   })
}
// 扇形绘制
export const createSector= ([cx,cy],r,r0,startAngle=5,endAngle=6,style)=> {
    let defaultStyle = {
        fill: 'none',
        stroke: '#F00',
    }
   return new zrender.Sector({
    shape: {
        cx,
        cy,
        r,
        r0,
        startAngle,
        endAngle
    },
    style:configStyle(defaultStyle,style)
   })
}
// 矩形形绘制
export const createRect= (x,y,width,height,style)=> {
    let defaultStyle = {
        fill: '#ffffff',
        stroke: '#000000',
    }
   return new zrender.Rect({
    shape: {
        x,
        y,
        width,
        height
    },
    style:configStyle(defaultStyle,style)
   })
}

export const creatText =(text,color,fontsize=12)=> {
  return  new zrender.Text({
        style:{
            text,
            font:{
                fontWeight :700,
            },
            fontSize:fontsize,
            fill:color,
        }
    })
} 
export const creatImg =(url,[x,y],[width,height])=> {
    return  new zrender.Image({
          style:{
              image:url,
              x:x,
              y:y,
              width,
              height
          }
      })
  } 

export const creatIsogon =()=> {
    return  new zrender.Isogon({
        shape:{
            x:250,
            y:250,
            r:30,
            n:4 
        }, 
      })
  } 

  export const creatLine =([x1,y1],[x2,y2])=> {
    return  new zrender.Line({
        shape:{
            x1,
            y1,
            x2,
            y2 
        }, 
      })
  } 

